Java Database Programming with JDBC Java Database Programming with JDBC
by Pratik Patel
Coriolis, The Coriolis Group
ISBN: 1576100561   Pub Date: 10/01/96
  

Previous Table of Contents Next


The HTML File That Calls The Applet

We need to call this applet from an HTML file, which is shown in Listing 4.10. We don’t pass in any properties, but we could easily include a default data source URL and user name that the applet would read in before initializing the user interface, and then set the appropriate TextField to show these defaults. Note that we set the width and height carefully in the <APPLET> tag. This is to make sure that our applet’s user interface has enough room to be properly laid out.

Listing 4.10 HTML code to call the interactive query applet.

<HTML>
<HEAD>
<TITLE>JDBC Client Applet - Interactive SQL Command Util</TITLE>
</HEAD>
<BODY>
<H1>Interactive JDBC SQL Query Applet</H1>
<hr>

<applet code=IQ.class width=450 height=350>
</applet>

<hr>
</BODY>
</HTML>

The Final Product

Figure 4.3 shows a screen shot of the completed applet, and Figure 4.4 shows the applet running. Not too shabby for our first try. We’ve covered a lot of ground in creating this applet, so let’s take some time to recap the important details. We learned how to:


Figure 4.3  The completed Interactive Query applet.


Figure 4.4  The Interactive Query applet running.

  Open a connection to a data source
  Connect a Statement object to the data source via the connection
  Execute a query
  Get MetaData information about the result of the query
  Use the MetaData information to properly get the results row-by-row, column-by-column
  Close the connection

To use the applet, you can load the HTML file in a Java-enabled Web browser, or you can start the applet from the command line:

bash$ appletviewer IQ.html &

Don’t forget, if you have problems finding the class file or the driver, set the CLASSPATH. See Chapter 3 for more help on this topic.

Coming Up Next

In the next chapter, we’ll explore the bridge between ODBC and JDBC. You’ll see how easy it is to use existing ODBC drivers with JDBC, and learn some of the fine points of the relation, similarity, and difference between the two database connectivity standards. You won’t want to miss this one; the author, Karl Moss, is also the author of the Sun/Intersolv ODBC-JDBC bridge included in the JDBC package.


Previous Table of Contents Next